import requests
from lxml import etree


def parse_url():
    url = 'https://news.163.com/'
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3608.4 Safari/537.36"}
    html = requests.get(url, headers=headers).text
    html_content = etree.HTML(html)
    print(html_content)
    return html_content


def content(html_content):
    content_list = []
    title = html_content.xpath('//div[@class="mt35 mod_hot_rank clearfix"]/div[@class="idx_cm_title"]/a/text()')[0]
    content = html_content.xpath('//div[@class="mt35 mod_hot_rank clearfix"]/ul/li/a/text()')
    count = html_content.xpath('//div[@class="mt35 mod_hot_rank clearfix"]/ul/li/span/text()')
    for i in content:
        item = {}
        item["content"] = i
        for x in count:
            item["count"] = x
        content_list.append(item)
    for x in content_list:
        print('内容：{}, 热度：{}'.format(x["content"], x["count"]))





if __name__ == '__main__':
    html_content = parse_url()
    content = content(html_content)





